﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Xml.Linq
Imports GenDotNet.Task.Common
Imports GenDotNet.ObjectModel
Imports <xmlns:orm="http://kadgen.com/KADORM.xsd">

Namespace GenInputMetadata
   Public Class KeyData
      Inherits BaseData
      Implements IKeyData


      Private Shared Function Load( _
             ByVal rootData As RootData, _
             ByVal element As XElement) _
             As KeyData
         Dim ret As New KeyData(rootData, element)
         Dim xDoc = element.Document
         Return ret
      End Function

      Public Shared Function Load( _
               ByVal rootData As RootData, _
               ByVal elements As IEnumerable(Of XElement)) _
               As List(Of IKeyData)
         Dim ret = New List(Of IKeyData)
         For Each XElement In elements
            ret.Add(Load(RootData, XElement))
         Next
         Return ret
      End Function

      Private Sub New(ByVal rootData As RootData, _
                     ByVal element As XElement)
         MyBase.New(rootData, element)
      End Sub

      Public ReadOnly Property ChildColumn() _
               As String _
               Implements IKeyData.ChildColumn
         Get
            Return Element.@ChildColumn
         End Get
      End Property

      Public ReadOnly Property ChildObjectName() _
               As String _
               Implements IKeyData.ChildObjectName
         Get
            Return Element.@ChildObject
         End Get
      End Property

      Public ReadOnly Property ChildProperty() _
               As String _
               Implements IKeyData.ChildProperty
         Get
            Return Element.@ChildProperty
         End Get
      End Property

      Public ReadOnly Property ChildTable() _
               As String _
               Implements IKeyData.ChildTable
         Get
            Return Element.@ChildTable
         End Get
      End Property

      Public ReadOnly Property ParentColumn() _
               As String _
               Implements IKeyData.ParentColumn
         Get
            Return Element.@ParentColumn
         End Get
      End Property

      Public ReadOnly Property ParentObjectName() _
               As String _
               Implements IKeyData.ParentObjectName
         Get
            Return Element.@ParentObject
         End Get
      End Property

      Public ReadOnly Property ParentProperty() _
               As String _
               Implements IKeyData.ParentProperty
         Get
            Return Element.@ParentProperty
         End Get
      End Property

      Public ReadOnly Property ParentTable() _
               As String _
               Implements IKeyData.ParentTable
         Get
            Return Element.@ParentTable
         End Get
      End Property

      Public ReadOnly Property ChildObjectData() _
               As IObjectData _
               Implements IKeyData.ChildObjectData
         Get
            Return RootData.GetObject(ChildObjectName)
         End Get
      End Property

      Public ReadOnly Property ParentObjectData() _
               As IObjectData _
               Implements IKeyData.ParentObjectData
         Get
            Return RootData.GetObject(ParentObjectName)
         End Get
      End Property

   End Class
End Namespace
